package com.winglinks.jobs;

import com.winglinks.domain.ModelType;
import com.winglinks.service.publish.PublishService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Slf4j
@Component
@EnableScheduling // 开启定时任务
public class JobClient {
    @Autowired
    PublishService publishService;

    @Value("${job.scheduled}")
    private String jobScheduled;

    @PostConstruct
    public void print(){
        System.out.println(jobScheduled);
    }

    @Scheduled(cron = "${job.scheduled}") // cron 表达式，每2秒执行
    public void sensoreRANG(){
        try {
            publishService.publishMqttMsg(ModelType.RANGE.getModel(), "1301021300784693","1aca318c69d24263b8f9f531f490c64a","gateway2","gateway2","gateway2");
            publishService.publishMqttMsg(ModelType.RANGE.getModel(), "402891D75D4A0F68","418977d332e9421aa920564d5e1ee8a9","gateway3","gateway3","gateway3");
            publishService.publishMqttMsg(ModelType.RANGE.getModel(), "402891D75D4A0F68","a8339b1f1fe9469282048de8e95ad86b","gateway3","gateway3","gateway3");
            publishService.publishMqttMsg(ModelType.RANGE.getModel(), "402891D75D4A0F68","5e69b79958ec4e4aae112cc72771b832","gateway3","gateway3","gateway3");
        }catch (Exception e){
            log.error("执行MQTT定时任务异常", e);
        }
    }

    @Scheduled(cron = "${job.scheduled}") // cron 表达式，每2秒执行
    public void sensoreDPMT(){
        try {
            publishService.publishMqttMsg(ModelType.DPMT.getModel(),"1301021300772825","f159de4bd44e45a0a3f84d46b1247bc1","gateway1","gateway1","gateway1");
            publishService.publishMqttMsg(ModelType.DPMT.getModel(),"1301021300772825","94820c76656341ecb53dad7bcb565ef0","gateway1","gateway1","gateway1");
            publishService.publishMqttMsg(ModelType.DPMT.getModel(),"1301021300784693","946134c7fb674cdc8ed0c779716752db","gateway2","gateway2","gateway2");
            publishService.publishMqttMsg(ModelType.DPMT.getModel(),"1301021300784693","bea556fb1c5447169383a4c762936cea","gateway2","gateway2","gateway2");
            publishService.publishMqttMsg(ModelType.DPMT.getModel(),"402891D75D4A0F68","acdf4aa5f56b46f488ebe45ac463bbb5","gateway3","gateway3","gateway3");
        }catch (Exception e){
            log.error("执行MQTT定时任务异常", e);
        }
    }

    @Scheduled(cron = "${job.scheduled}") // cron 表达式，每2秒执行
    public void sensoreDPVN(){
        try {
            publishService.publishMqttMsg(ModelType.DPVN.getModel(),"1301021300772825","5c5ec10d05ea44dd86314f21441e39b2","gateway1","gateway1","gateway1");
            publishService.publishMqttMsg(ModelType.DPVN.getModel(),"1301021300772825","967c725d2c0c45cda7ca4cc7331f262e","gateway1","gateway1","gateway1");
            publishService.publishMqttMsg(ModelType.DPVN.getModel(),"1301021300772825","2e96f84e93cc4ff888c3d8dfd035e640","gateway1","gateway1","gateway1");
            publishService.publishMqttMsg(ModelType.DPVN.getModel(),"1301021300772825","a49dcbd73a474f1bab868d03f26e67a9","gateway1","gateway1","gateway1");
            publishService.publishMqttMsg(ModelType.DPVN.getModel(),"1301021300772825","d616dc6253bc4a0481038760042acfd1","gateway1","gateway1","gateway1");
            publishService.publishMqttMsg(ModelType.DPVN.getModel(),"1301021300772825","d4ca5f7d634f465bbc66462271544269","gateway1","gateway1","gateway1");
            publishService.publishMqttMsg(ModelType.DPVN.getModel(),"1301021300772825","0edab6fa25d04d20955607eada489e3b","gateway1","gateway1","gateway1");
            publishService.publishMqttMsg(ModelType.DPVN.getModel(),"1301021300772825","fd7d06445c4e4edc82e919a33b543640","gateway1","gateway1","gateway1");
            publishService.publishMqttMsg(ModelType.DPVN.getModel(),"1301021300772825","9ac85b577e364284a1b323af9e3840cf","gateway1","gateway1","gateway1");
            publishService.publishMqttMsg(ModelType.DPVN.getModel(),"1301021300772825","911550a7e3784acf9fb2bbc1861a4d88","gateway1","gateway1","gateway1");
            publishService.publishMqttMsg(ModelType.DPVN.getModel(),"1301021300784693","c5669bb713e949f49343b0c8566a5ba5","gateway2","gateway2","gateway2");
            publishService.publishMqttMsg(ModelType.DPVN.getModel(),"402891D75D4A0F68","cba1f6bdbd954ca88331e1cb01de2ff5","gateway3","gateway3","gateway3");
        }catch (Exception e){
            log.error("执行MQTT定时任务异常", e);
        }
    }

    @Scheduled(cron = "${job.scheduled}") // cron 表达式，每2秒执行
    public void sensoreTEMP(){
        try {
            publishService.publishMqttMsg(ModelType.TEMP.getModel(),"1301021300784693","b3274bd19cad489595d869055a58ce90","gateway2","gateway2","gateway2");
            publishService.publishMqttMsg(ModelType.TEMP.getModel(),"1301021300784693","aa8487627fbd4c68a9295971d2115107","gateway2","gateway2","gateway2");
            publishService.publishMqttMsg(ModelType.TEMP.getModel(),"402891D75D4A0F68","525d583ecc7846e3ad12f012c17f6094","gateway3","gateway3","gateway3");
        }catch (Exception e){
            log.error("执行MQTT定时任务异常", e);
        }
    }

    @Scheduled(cron = "${job.scheduled}")
    public void sensoreAtmosphere(){
        try {
            publishService.publishMqttMsg(ModelType.ATOMSPHERE.getModel(),"11M221122WFGL0002","11M221122WFGL0002","atmosphere","atmosphere","atmosphere");
        }catch (Exception e){
            log.error("执行MQTT定时任务异常", e);
        }
    }

    @Scheduled(cron = "${job.scheduled}")
    public void sensoreIceCover(){
        try {
            publishService.publishMqttMsg(ModelType.ICECOVER.getModel(),"11M221122FBGL0002","11M221122FBGL0002","icecover","icecover","icecover");
        }catch (Exception e){
            log.error("执行MQTT定时任务异常", e);
        }
    }

    @Scheduled(cron = "${job.scheduled}")
    public void sensoreImage(){
        try {
            publishService.publishMqttMsg(ModelType.IMAGE.getModel(),"11M221122PVGL0002","11M221122PVGL0002","image","image","image");
        }catch (Exception e){
            log.error("执行MQTT定时任务异常", e);
        }
    }
}
